﻿// JavaScript Document
//绑定方式
//$("#mbListBox").smartFloat();
$.fn.smartFloat = function() {
	var position = function(element) {
		var //top = element.position().top,
		top=element.offset()['top'],
		pos = element.css("position"),
		topblankheight=element.height();
		element.after("<div id=\"tempblank\"></div>");
		$("#tempblank").height(topblankheight);
		$("#tempblank").hide();
		$(window).scroll(function() {
			var scrolls = $(this).scrollTop();
			//alerts(scrolls+"+"+top);
			if (scrolls > top) {
				//alert(scrolls+"+"+top);
			//	element.height("auto");	
				$("#tempblank").show();
				if (window.XMLHttpRequest) {
					element.css({
						position: "fixed",
						top: 0
					});	
				} else {
					element.css({
						top: scrolls
					});	
				}
			}else {
				//element.height("auto");	
				$("#tempblank").hide();
				element.css({
					position: pos,
					top: top
				});	
			}
		});
	};
	return $(this).each(function() {
		position($(this));						 
	});
};

$.fn.smartFloat2 = function() {
	var position = function(element) {
		var //top = element.position().top,
		top=element.offset()['top'],
		pos = element.css("position"),
		topblankheight=element.height();
		element.after("<div id=\"tempblank\"></div>");
		$("#tempblank").height(topblankheight);
		$("#tempblank").hide();
		$(window).scroll(function() {
			var scrolls = $(this).scrollTop();
			//alerts(scrolls+"+"+top);
			if (scrolls > top) {
			//	alerts(scrolls+"+"+top+pos);
			//	element.height("auto");	
				$("#tempblank").show();
				element.addClass("header_f");
				if (window.XMLHttpRequest) {
					element.css({
						position: "fixed",
						top: 0
					});	
				} else {
					element.css({
						top: scrolls
					});	
				}
			}else {
				//element.height("auto");
				element.removeClass("header_f");
				$("#tempblank").hide();
				element.css({
					position: pos
					//top: top
				});	
			}
		});
	};
	return $(this).each(function() {
		position($(this));						 
	});
};